package com.xinan.dmgl.cggl;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.sql.Timestamp;
import java.util.List;
import java.sql.Date;

@TableBind(tableName = "cpgl_ck")
public class CpglCk extends Model<CpglCk>{
    public static final CpglCk dao = new CpglCk();

    //columns START
    private String ID = "id";  //
    private String WPID = "wpid";  //商品id
    private String CKSL = "cksl";  //出库数量
    private String CKYY = "ckyy";  //出库原因 1 销售出库 2 退货出库3领用出库
    private String CKJE = "ckje";  //

    public void setId(int value) {
        set(ID, value);
    }

	public int getId() {
		return get(ID);
	}
    public void setWpid(String value) {
        set(WPID, value);
    }

	public String getWpid() {
		return get(WPID);
	}
    public void setCksl(String value) {
        set(CKSL, value);
    }

	public String getCksl() {
		return get(CKSL);
	}
    public void setCkyy(String value) {
        set(CKYY, value);
    }

	public String getCkyy() {
		return get(CKYY);
	}
    public void setCkje(String value) {
        set(CKJE, value);
    }

	public String getCkje() {
		return get(CKJE);
	}
	//columns END

    public List<CpglCk> findAll() {
        return find("select * from cpgl_ck");
    }
    /**
     * @param   where
     * @return  Record
     */
    public List<Record> findAlls(String where) {
        String sqlExp = " from cpgl_ck";
        if(StringKit.notBlank(where)){
                sqlExp += " where " + where;
        }
                return Db.find( "select *,(select a.wpmc from cggl_wp a where wpid=a.id)  as wpmc" +sqlExp );

    }

    public Page<CpglCk> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from cpgl_ck";
        if(StringKit.notBlank(where)){
            sqlExp += " where  (ckyy =3  or ckyy =4)  and " + where;
        }else {
            sqlExp += " where  (ckyy =3  or ckyy =4)" + where;

        }
        
        return paginate(pageNumber, pageSize, "select * ,(select a.wpmc from cggl_wp a where wpid=a.id)  as wpmc", sqlExp);
    }
    
    public Page<CpglCk> pagetj(int pageNumber, int pageSize, String where) {
        String sqlExp = " from ( select a.* , sum(a.cksl) as cksls ,(select b.wpmc from cggl_wp b where a.wpid=b.id)  as wpmc from cpgl_ck a  group by  a.wpid) b" ;
      //  String sql ="   "
        if(StringKit.notBlank(where)){
            sqlExp += " where  " + where;
        }
        String group=" group  by wpid ";
        return paginate(pageNumber, pageSize, "select * ", sqlExp);
    }
}

